
<cffunction name="dumpvar" output="true">
  <cfargument name="daVar" required="true">
	<cfdump var="#daVar#"> 
</cffunction>

<cffunction name="cfdir" output="false">
	<cfargument name="daDir" required="true">
	<cfdirectory action="list" name="daDirs" directory="#daDir#">
	<cfreturn daDirs>
</cffunction>

<cfscript>
        
      function visitAllDirs (dirTarget) {
  			var i = 0;
  			var dirSize = 0;
  			var subDirs = arrayNew(1);
  			dir = createObject("java","java.io.File").init(JavaCast("string",dirTarget));
        //writeoutput("Exists: "& dir.exists() & " Target:"&dirTarget& " " & subDirCount & "<br />");
        if (dir.isDirectory()) {
            subDirCount = subDirCount + 1;
            fileSep = dir.separator;
	  				children = dir.listFiles();
            for (i=0; i LT arrayLen(children); i=i+1) {
	            	if (children[i+1].isDirectory()){
	              	arrayAppend(subDirs,dirTarget&fileSep&children[i+1].getName());
	            	}
	            	else if (children[i+1].isFile()){
	            		dirSize = dirSize + children[i+1].length();
	            		totalDirsSize = totalDirsSize + children[i+1].length();	            		
	            	}
            }
            foldersAndSizes[subDirCount]["name"] = dir.getName();
            foldersAndSizes[subDirCount]["size"] = decimalformat((dirSize/1024)/1024) & "MB";
            for (i=0; i LT arrayLen(subDirs); i=i+1) {
             	visitAllDirs(subDirs[i+1]);
            }
        } 
        else {
        	// writeoutput("Not Dir:" & dir.getName());
        }
        return foldersAndSizes;
      }

      function getDirectorySizes (targetDir) {
        subDirCount = 0;
  			foldersAndSizes = arrayNew(1);
  			totalDirsSize = 0;
     		theseDirs = visitAllDirs(targetDir,0);
        theseDirs[subDirCount+1]["name"] = "All Folders";
        theseDirs[subDirCount+1]["size"] = decimalformat((totalDirsSize/1024)/1024) & "MB";
     		return theseDirs;
      }
      
        targetDir = "C:\build"; // NO TRAILING SLASH!!

currentDirectory = expandPath("./");
currentDirectory = replace(currentDirectory,"\","/","all");
urls[1] = createObject("java","java.net.URL").init("file:#currentdirectory#");
GetObject = createObject("java","coldfusion.bootstrap.BootstrapClassLoader").SystemClassLoader.newInstance(urls).loadClass("DirFilter").newInstance();
dumpvar(GetObject.doFileFilterDirectoryListing(javacast("string",targetDir)));   

   
				REQUEST.timer_start = getTickcount();
	     		cfd = cfDir(targetDir);
				REQUEST.timer_end = getTickcount();
				writeoutput("CFdir Time:"&REQUEST.timer_end - REQUEST.timer_start);
				REQUEST.timer_start = getTickcount();
	     		jfile = getDirectorySizes(targetDir);
				REQUEST.timer_end = getTickcount();
				writeoutput("JFile Time:"&REQUEST.timer_end - REQUEST.timer_start);
      
    /*  
    File[] files = dir.listFiles();
    
    FileFilter fileFilter = new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }
    };
    // one line java file list
		fileList = createObject("java", "java.util.Arrays").asList( createObject("java", "java.io.File").init(LOCAL_DIRECTORY).list() );    
		
		files = dir.listFiles(fileFilter);
    */

</cfscript>
</body></html>